package edu.nus.mtech.sem1.ca.txn;

import java.util.Date;

import edu.nus.mtech.sem1.ca.plan.PlanType;
import edu.nus.mtech.sem1.ca.utils.TelephonyUtils;

public class Transaction {
	
	private String lineNumber;
	private String numberCalled;
	private Date dateOfCall;
	private Integer timeOfCall;
	private Float durationOfCall; //there is no need for float here considering we have per minute billing. but still, you know, Singtel would do anything to hold market share
	private PlanType lineType;
	private CallType callType;
	
	
	public String getLineNumber() {
		return lineNumber;
	}
	public void setLineNumber(String lineNumber) {
		this.lineNumber = lineNumber;
	}
	public String getNumberCalled() {
		return numberCalled;
	}
	public void setNumberCalled(String numberCalled) {
		this.numberCalled = numberCalled;
	}
	public Date getDateOfCall() {
		return dateOfCall;
	}
	public void setDateOfCall(Date dateOfCall) {
		this.dateOfCall = dateOfCall;
	}
	
	public Integer getTimeOfCall() {
		return timeOfCall;
	}
	public void setTimeOfCall(Integer timeOfCall) {
		this.timeOfCall = timeOfCall;
	}
	public Float getDurationOfCall() {
		return durationOfCall;
	}
	public void setDurationOfCall(Float durationOfCall) {
		this.durationOfCall = durationOfCall;
	}

	public PlanType getLineType() {
		return lineType;
	}
	public void setLineType(PlanType lineType) {
		this.lineType = lineType;
	}
	public CallType getCallType() {
		return callType;
	}
	public void setCallType(CallType callType) {
		this.callType = callType;
	}
	

	@Override
	public boolean equals(Object transactionObj) {
		boolean allResult=false;
		
		if (transactionObj!=null && transactionObj instanceof Transaction){
			Transaction incomingTransaction=(Transaction)transactionObj;
			
			if (incomingTransaction.getLineNumber().equals(lineNumber)){
				allResult=true;
			}
			if (incomingTransaction.getNumberCalled().equals(numberCalled)){
				allResult=allResult && true;
			}
			if (incomingTransaction.getDateOfCall().equals(dateOfCall)){
				allResult=allResult && true;
			}
			if (incomingTransaction.getTimeOfCall().equals(timeOfCall)){
				allResult=allResult && true;
			}
			if (incomingTransaction.getDurationOfCall().equals(durationOfCall)){
				allResult=allResult && true;
			}
			if (incomingTransaction.getLineType().equals(lineType)){
				allResult=allResult && true;
			}
			if (incomingTransaction.getCallType().equals(callType)){
				allResult=allResult && true;
			}
			
		}
		return allResult;
	}

	
	@Override
	public int hashCode() {
		//Had to override the hashcode method because we have overridden the equals method.
		// Just multiplying with a good primary number to avoid false duplicates
		int hashCode=(TelephonyUtils.getHashCode(lineNumber)*73)+TelephonyUtils.getHashCode(numberCalled)+TelephonyUtils.getHashCode(dateOfCall)+TelephonyUtils.getHashCode(timeOfCall)+TelephonyUtils.getHashCode(durationOfCall)+TelephonyUtils.getHashCode(lineType)+TelephonyUtils.getHashCode(callType);
		return hashCode;
		
	}

	@Override
	public String toString() {
		return(lineNumber+"::"+numberCalled+"::"+dateOfCall+"::"+timeOfCall+"::"+durationOfCall+"::"+lineType+"::"+callType);
	}
	
}
